import React, { useState } from "react";
import { Affix, Menu } from "antd";
import Link from "next/link";

const Nav = () => {
  const [top, setTop] = useState(44.8);
  // const [selectKey,setSelectKey] = useState(1);
  // const changeKey=()=>{
  //   let url = window.location.href;
  //   console.log(url.split('/')[3]);
  //   let path = url.split('/')[3]
  //   setSelectKey(path)
  // }
  // defaultSelectedKeys={1} selectedKeys={selectKey} onClick={()=>{changeKey()}}

  return (
    <div className="nav">
      <Affix offsetTop={top}>
        <Menu mode="horizontal">
          <Menu.Item key={1}>
            <Link href="/">首页</Link>
          </Menu.Item>
          <Menu.Item key={2}>
            <Link href="/algorithm">算法</Link>
          </Menu.Item>
          <Menu.Item key={3}>
            <Link href="/knowledge">知识</Link>
          </Menu.Item>
          <Menu.Item key={4}>
            <Link href="/life">生活</Link>
          </Menu.Item>
          <Menu.Item key={5}>
            <Link href="/topic">讨论</Link>
          </Menu.Item>
        </Menu>
      </Affix>
    </div>
  );
};

export default Nav;
